/**
 * Copyright &copy; com.nmf
 */
package com.nmf.site.biz.pdf.service;

import java.util.List;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.nmf.site.common.PageDb;
import org.apache.commons.lang3.StringUtils;

import com.nmf.dao.gen.bean.BizPdf;
import com.nmf.dao.gen.bean.BizPdfExample;
import com.nmf.dao.gen.BizPdfMapper;
import com.nmf.site.common.enums.DelFlagEnums;
import com.nmf.site.common.persistence.Page;
import com.nmf.site.common.utils.IdGenerater;

/**
 * pdfService
 * @author bm
 * @version 2019-02-14
 */
@Service
@Transactional(readOnly = true)
public class BizPdfService{

	@Autowired
	BizPdfMapper bizPdfMapper;
	@Autowired
	IdGenerater idGenerater;
	
	public BizPdf get(String no) {
		return bizPdfMapper.selectByPrimaryKey(no);
	}
	
	public List<BizPdf> findList(BizPdf bizPdf) {
		BizPdfExample bizPdfExample = new BizPdfExample();
		BizPdfExample.Criteria criteria = bizPdfExample.createCriteria();
		
		return bizPdfMapper.selectByExample(bizPdfExample);
	}
	
	public Page<BizPdf> findPage(Page<BizPdf> page, BizPdf bizPdf) {
		BizPdfExample bizPdfExample = new BizPdfExample();
		BizPdfExample.Criteria criteria = bizPdfExample.createCriteria();
		
		bizPdfExample.setPage(page);
		
		List<BizPdf> dlist = bizPdfMapper.selectByExample(bizPdfExample);
		page.setList(dlist);
		page.setCount(bizPdfMapper.countByExample(bizPdfExample));
		
		return page;
	}
	
	@Transactional(readOnly = false)
	public void save(BizPdf bizPdf) {
		if(StringUtils.isNotEmpty(bizPdf.getId())&&get(bizPdf.getId())!=null) {
			bizPdfMapper.updateByPrimaryKeySelective(bizPdf);
		}else {
			Date date = new Date();
			bizPdf.setCreateDate(date);
			bizPdf.setId(idGenerater.genClsNo("bizPdf"));
			bizPdf.setUpdateDate(date);
			bizPdfMapper.insertSelective(bizPdf);
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(BizPdf bizPdf) {
		bizPdfMapper.deleteByPrimaryKey(bizPdf.getId());
	}
	
}